<template>
  <div>
    <!-- 顶部搜索 -->
    <div class="search-row search-box">
      <el-form :inline="true" :model="searchParams" class="demo-form-inline">
        <el-form-item label="人审时间">
          <el-date-picker
            v-model="timeRange"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
            @change="initDate"
          ></el-date-picker>
        </el-form-item>

        <el-form-item label="内容所属模块">
          <el-select v-model="searchParams.topicType" placeholder="请选择">
            <el-option
              v-for="item in topicOptions"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="success" icon="el-icon-search" @click="handleSearch"
            >查询</el-button
          >
        </el-form-item>

        <el-form-item>
          <el-button type="success" plain @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!--table 刷新-->
    <div class="table-conBtn">
      <freshCom @searchList="searchList"></freshCom>
    </div>

    <!--table 列表-->
    <div class="table-box">
      <el-table
        ref="table"
        :data="tableData"
        v-loading="loading"
        :fit="true"
        max-height="490"
        stripe
      >
        <el-table-column type="index" label="序号">
          <template slot-scope="scope">
            {{
              scope.$index
                | filterPage(pagingParams.pageNum, pagingParams.pageSize)
            }}
          </template>
        </el-table-column>

        <el-table-column label="类型" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.labelType">{{
              scope.row.labelType | jobTypeFilter
            }}</span>
            <span v-else> --- </span>
          </template>
        </el-table-column>

        <el-table-column label="配文" prop="content" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.content" v-html="filterContent(scope.row)">
              {{ scope.row.content }}
            </span>
            <span v-else> --- </span>
          </template>
        </el-table-column>

        <el-table-column label="视图" prop="images" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.images && scope.row.images.length > 0">
              <listImgShow :imgInfo="scope.row.images"></listImgShow>
            </span>
            <span v-else>-</span>
          </template>
        </el-table-column>

        <el-table-column label="创建时间" prop="createdDate" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.createdDate }}</span>
          </template>
        </el-table-column>

        <el-table-column label="内容所属模块" prop="topic" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.topic.type | topicFilter }}</span>
          </template>
        </el-table-column>

        <el-table-column label="未通过原因" prop="reason" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.reason">{{ scope.row.reason }}</span>
            <span v-else> --- </span>
          </template>
        </el-table-column>

        <el-table-column label="人审时间" prop="peopleAuditTime" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.peopleAuditTime">{{
              scope.row.peopleAuditTime
            }}</span>
            <span v-else> --- </span>
          </template>
        </el-table-column>

        <el-table-column label="审核人" prop="auditingUser.name" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.auditingUser.name">{{
              scope.row.auditingUser.name
            }}</span>
            <span v-else> --- </span>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!--分页-全局组件-->
    <pageCom
      :searchParams="pagingParams"
      :total="total"
      @searchList="searchList"
    ></pageCom>
  </div>
</template>

<script>
import { filterCon } from '@utils/pubFunction'
import { getCommentList } from '@/api/commentCheck/unpassList'
import { sysNormalDisable } from '@utils/dictionariesFunc'

const jobType = {
  TEXT: { text: '图文' },
  VIDEO: { text: '短视频' }
}

const topicList = {
  2: { text: '活动帖子' },
  3: { text: '作品' },
  4: { text: '作业' },
  5: { text: '作品小视频' },
  6: { text: '公开课' },
  8: { text: '动态' },
  9: { text: '临摹主贴' },
  10: { text: '临摹跟帖' },
  13: { text: '阅读' },
  14: { text: '长视频' }
}

export default {
  msg: '活动帖子',

  data() {
    return {
      total: 0,
      loading: true,

      tableData: [],
      timeRange: [],
      topicOptions: [
        //内容所属模块
        { dictLabel: '全部', dictValue: '' }
      ],

      pagingParams: {
        pageNum: 1,
        pageSize: 10
      },

      searchParams: {
        timeType: 3, // 时间类型
        startTime: '',
        endTime: '',
        topicType: '',
        peopleAuditStatus: 2, // 人审状态
        sort: 'manualAuditTime,desc', // 人审时间倒序
        userValue: '' // 大鹏号
      }
    }
  },

  computed: {
    dpAccount() {
      return this.$route.query.dpAccount
    }
  },

  filters: {
    jobTypeFilter(type) {
      return jobType[type].text
    },

    topicFilter(type) {
      return topicList[type].text
    }
  },

  async created() {
    if (this.dpAccount) {
      this.searchParams.userValue = this.dpAccount
    }

    const data1 = await sysNormalDisable('sys_topic_type')
    this.topicOptions = this.topicOptions.concat(data1)

    this.searchList()
  },

  methods: {
     initDate(val){
      if(!val){
        this.searchParams.startTime = ''
        this.searchParams.endTime = ''  
      }else{
        this.searchParams.startTime = val[0]
        this.searchParams.endTime = val[1]
      }
    },
    searchList() {
      this.loading = true

      if (this.timeRange) {
        this.searchParams.startTime = this.timeRange[0]
        this.searchParams.endTime = this.timeRange[1]
      }

      let params = { ...this.searchParams, ...this.pagingParams }

      getCommentList(
        params,
        (res) => {
          this.tableData = res.rows
          this.total = res.total
          this.loading = false
        },
        (err) => {
          this.$message({
            message: err.message,
            type: 'warning'
          })
        }
      )
    },

    // 过滤返回评论内容
    filterContent(item) {
      return filterCon(item)
    },

    // 查询
    handleSearch() {
      this.pagingParams.pageNum = 1
      this.searchList()
    },

    // 重置
    handleReset() {
      this.timeRange = []
      this.searchParams.topicType = ''
      this.searchParams.startTime = ''
      this.searchParams.endTime = ''
    }
  }
}
</script>
